package net.arvin.mobilebanksystem.fragment;

import net.arvin.mobilebanksystem.R;
import net.arvin.mobilebanksystem.activity.MainActivity;
import net.arvin.mobilebanksystem.activity.UserInfoActivity;
import net.arvin.utils.PreferenceUtils;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

@SuppressLint("ValidFragment")
public class MenuFragment extends Fragment implements OnClickListener {

	private RelativeLayout mainPage;
	private RelativeLayout lifePage;
	private RelativeLayout helperPage;
	private RelativeLayout minePage;
	public SlidingMenu mSlidingMenu;

	public MenuFragment() {
		super();
	}

	public MenuFragment(SlidingMenu sm) {
		this();
		mSlidingMenu = sm;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_menu, null);
		init(view);
		return view;
	}

	private void init(View view) {
		initView(view);
		initListener();
	}

	private void initListener() {
		mainPage.setOnClickListener(this);
		lifePage.setOnClickListener(this);
		helperPage.setOnClickListener(this);
		minePage.setOnClickListener(this);
	}

	private void initView(View view) {
		mainPage = (RelativeLayout) view.findViewById(R.id.main_page);
		lifePage = (RelativeLayout) view.findViewById(R.id.life_page);
		helperPage = (RelativeLayout) view.findViewById(R.id.helper_page);
		minePage = (RelativeLayout) view.findViewById(R.id.mine_page);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.main_page:
			MainActivity.mainActivity.switchContent(new MainPageFragment(),true);
			MainActivity.mainActivity.setTitleTv("首页");
			mSlidingMenu.showContent();
			break;
		case R.id.life_page:
			MainActivity.mainActivity.switchContent(new LifeFragment(),true);
			MainActivity.mainActivity.setTitleTv("生活");
			mSlidingMenu.showContent();
			break;
		case R.id.helper_page:
			MainActivity.mainActivity.switchContent(new HelperFragment(),true);
			MainActivity.mainActivity.setTitleTv("助手");
			mSlidingMenu.showContent();
			break;
		case R.id.mine_page:
			MainActivity.mainActivity.switchContent(new MineFragment(),true);
			MainActivity.mainActivity.setTitleTv("我的");
			mSlidingMenu.showContent();
			break;
		}
	}

	@SuppressWarnings("unused")
	private void logout() {
		PreferenceUtils.modifyStringValueInPreferences(PreferenceUtils.Token,
				null, getActivity());
		Intent tent = new Intent();
		tent.setClass(getActivity(), UserInfoActivity.class);
		getActivity().startActivity(tent);
		getActivity().finish();

	}
}
